package Test11_16;

import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

public class Test01 {
    public static void main(String[] args) {
        //把1-10000内所有的质数写入文件，十个一行，每个用空格隔开
        try {
            FileOutputStream fileOutputStream = new FileOutputStream("D:\\aaa\\chapter.txt");
            int pos=0;
            int count=0;
            String s = "";
            for (int i = 3;i<=10000;i++){
                for (int j = 1;j*j<=i;j++){
                    if (i%j==0){
                        pos++;
                    }
                }
                if (pos==1){
                    count++;
                    s+=i;
                    s+=" ";

                }
                if (count==10){
                    s+="\n";
                    count=0;
                }
                pos=0;
            }
            byte a[] = s.getBytes();
            fileOutputStream.write(a);
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
